//
//  NewAddressLabelTextField.m
//  FD
//
//  Created by xiaofang wang on 2018/10/29.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "NewAddressLabelTextField.h"
@interface NewAddressLabelTextField()
//<UITextFieldDelegate>
@property (nonatomic, strong) UIView *bgView;
@end
@implementation NewAddressLabelTextField

- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title placeHolder:(NSString *)placehoder {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
        
        self.nameLb.text = title;
        self.textField.placeholder = placehoder;
        self.textField.font = [UIFont systemFontOfSize:15.0]; //1-19字号大小有点大
    }
    return self;
}


- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView];
    }
    return self;
}
- (void)setupView {
    
    
    //白色背景
    self.bgView.frame = self.bounds;
    [self addSubview:self.bgView];
//
//    CGFloat sh = self.bounds.size.height;
//    CGFloat sw = self.bounds.size.width;
//    CGFloat h = 20;
//    CGFloat y = (sh - h)*0.5;
//    self.nameLb.frame = CGRectMake(15, y, 100, h);
    [self addSubview:self.nameLb];
    
//    CGFloat tfw = sw - 10 - self.nameLb.rb_right;
    
//    self.textField.frame = CGRectMake(self.nameLb.rb_right, y, tfw, h);
    [self addSubview:self.textField];
    
    //设置代理
//    self.textField.delegate = self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.bgView.mas_left).offset(15);
        make.top.bottom.equalTo(self.bgView);
        make.width.height.mas_equalTo(100);
    }];
    
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLb.mas_right);
        make.top.bottom.equalTo(self.bgView);
        make.right.equalTo(self.bgView.mas_right).offset(-10);
    }];
}




//getter
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [UILabel new];
        _nameLb.numberOfLines = 0; //2019-2-22国际化显示不全
    }
    return _nameLb;
}
- (UITextField *)textField {
    if (!_textField) {
        _textField = [[UITextField alloc] init];
    }
    return _textField;
}


@end
